package scalaLearning.part1

object WordCount {
  def main(args: Array[String]): Unit = {
    val lines = Array("hello world hello Tim", "hello java hello java", "hello Tim Jim")
    val stringToInt: Map[String, Int] = lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.length))
    val reverse: List[(String, Int)] = stringToInt.toList.sortBy(_._2).reverse
    reverse.foreach(println)
  }
}
